package org.zsl.service;

import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Service;
import org.zsl.model.ResponseMsg;
import org.zsl.model.User;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserService {

    public Boolean login(User user) {


        if (user.getUsername().equals("admin") && user.getPassword().equals("123")) {
            return true;
        }

        return false;


    }


    public String login2(User user) {

        ResponseMsg responseMsg = new ResponseMsg();

        if (user.getUsername().equals("admin") && user.getPassword().equals("123")) {
            responseMsg.setSuccess(true);
        }else{
            responseMsg.setSuccess(true);
        }

        String result = JSON.toJSONString(responseMsg);
        System.out.println(result);


        return result;

    }

    public List<User> getList(){

        List<User> users = new ArrayList<>();

        User user1 = new User();
        user1.setUsername("admin");
        user1.setPassword("123");


        User user2 = new User();
        user2.setUsername("admin");
        user2.setPassword("123");

        User user3 = new User();
        user3.setUsername("admin");
        user3.setPassword("123");


         users.add(user1);
         users.add(user2);
        users.add(user3);


        return  users;

    }

    public ResponseMsg login3(User user) {

        ResponseMsg  responseMsg = new ResponseMsg();

        if(user.getUsername().equals("admin")&&user.getPassword().equals("123")){
             responseMsg.setSuccess(true);
        }else {
             responseMsg.setSuccess(false);
        }

        return  responseMsg;
    }

    public User getSingle(Integer userId) {

        User user = new User();
        user.setUsername("admin");
        user.setPassword("123");

        return  user;
    }

    public ResponseMsg add(User user) {

        return  null;
    }

    public ResponseMsg edit(User user) {

         if(user.getUserId()!=null){
              // 修改
         }else{
             //添加
         }
        return  null;
    }

    public ResponseMsg del(User userId) {

        return null;
    }
}
